<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>定时任务</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, shrink-to-fit=no"/>
    <meta name="renderer" content="webkit"/>
    <meta name="force-rendering" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <link rel="stylesheet" href="/static/public/libs/layui-v2.5.6/layui/css/layui.css">
    <link href="/static/public/libs/font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
    <link href="/static/admin/static/css/main.css" rel="stylesheet"/>
    <style>
        #file {
            width: 150px;
            height: 150px;
            border: 1px solid #dddddd;
            overflow: hidden;
            border-radius: 5px;
            cursor: pointer;
            text-align: center;
            line-height: 150px;
            font-size: 30px;
            color: #959393;
        }

        #uploadCoverDel {
            display: none;
            line-height: 150px;
            font-size: 30px;
            color: red;
            cursor: pointer;
            text-align: center;
            width: 150px;
            height: 150px;
            position: absolute;
            top: 0;
            z-index: 9999;
            background: #25262680;
        }
    </style>
</head>
<body>
<div class="p-container p-add-panel">
    <form class="layui-form" lay-filter="addForm">
        <div class="layui-input-inline" style="display: none;">
            <select lay-verify="" type="hidden"></select>
        </div>
        <input id="id" name="id" value="#(scheduled.id)" style="display: none">

        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="p-form-required">*</span>bean名称:
            </label>
            <div class="layui-input-block">
                <input type="text" id="taskKey" name="taskKey" value="#(scheduled.taskKey)" required
                       lay-verify="required" placeholder="bean名称"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="p-form-required">*</span>任务描述:
            </label>
            <div class="layui-input-block">
                <textarea name="taskDesc" id="taskDesc" placeholder="任务描述"
                          class="layui-textarea article-textarea" style="resize: none">
                    #(scheduled.taskDesc)
                </textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="p-form-required">*</span>任务表达式:
            </label>
            <div class="layui-input-block">
                <input type="text" id="taskCron" name="taskCron" placeholder="任务表达式"
                       autocomplete="off" class="layui-input" value="#(scheduled.taskCron)">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="p-form-required">*</span>是否自动启动:
            </label>
            <div class="layui-input-block">
                <select name="initStartFlag" lay-filter="isEnc" lay-verify="required">
                    <option value="0" #if(scheduled.initStartFlag== 0) selected #end>否</option>
                    <option value="1" #if(scheduled.initStartFlag== 1) selected #end>是</option>
                </select>
            </div>
        </div>
        <div class="add-btn-box">
            <button type="button" id="add" lay-submit lay-filter="addForm"
                    class="layui-btn layui-btn-normal p-submit-btn">确定
            </button>
            <button type="button" class="layui-btn layui-btn-primary p-cancel-btn">取消</button>
        </div>
    </form>
</div>

<script src="/static/public/libs/jquery/jquery-3.5.1.min.js"></script>
<script src="/static/public/libs/layui-v2.5.6/layui/layui.js"></script>
<script>
    layui.config({base: '/static/public/libs/layui-v2.5.6/layui/layui_exts/'})
        .extend({
            cron: "cron/cron"
        });
    let form, element, layer, upload, laydate, cron;
    layui.use(['layer', 'form', 'element', 'cron'], function () {
        form = layui.form;
        element = layui.element;
        layer = layui.layer;
        upload = layui.upload;
        laydate = layui.laydate;
        cron = layui.cron;
        //常规用法
        laydate.render({
            elem: '#overTime'
        });
        cron.render({
            elem: "#taskCron", // 绑定元素
            run: "/admin/scheduled/getNextExecTime?numTimes=10", // 获取最近运行时间的接口
            value: $("#taskCron").val(), // 默认值
            done: function (cronStr) {
                $("#taskCron").val(cronStr);
            },
        });
        // 表单提交
        form.on('submit(addForm)', function (data) {
            $.ajax({
                type: "POST",
                url: "/admin/scheduled/edit",
                contentType: "application/json",
                data: JSON.stringify(data.field),
                success: function (data) {
                    if (data.code === 200) {
                        parent.queryTable();
                        parent.layer.msg("添加成功", {icon: 1});
                        const index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    } else {
                        layer.msg(data.msg, {icon: 2});
                    }
                },
                error: function (data) {
                    layer.msg("添加失败", {icon: 2});
                }
            });
            return false;
        });
    });
    $(".p-cancel-btn").click(function () {
        const index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    });
</script>
</body>
</html>
